<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
import operatorUtil from './utils/operator_util'

export default {
  name: 'App',
  data () {
    return {
      callbackYesNoConfirm: null
    }
  },
  methods: {
    // 装载 Operaor token 为 axios
    loadJwtToken: function () {
      // var token = this.$cookie.get(this.$config.KEY_USER_TOKEN)
      var token = localStorage.getItem(this.$config.KEY_USER_TOKEN)
      if (token) {
        this.$axios.defaults.headers.common[this.$config.JWT_HEADER] = this.$config.JWT_PERFIX + token
      }
    },
    loadOperator: function () {
      var operator = JSON.parse(localStorage.getItem(this.$config.KEY_OPERATOR))
      if (operator) {
        operatorUtil.setOperator(this, operator)
        this.$router.updateRouters(operator.menuList)
        window.operator = operator
      }
    }
  },
  created () {
    // 获取 Operaor token
    this.loadJwtToken()
    this.loadOperator()
    /**
     * BUS 事件总线
     */
    // 装载 Operaor token
    this.$bus.$on('loadOperatorToken', () => {
      this.loadJwtToken()
    })
    // 注销
    this.$bus.$on('logout', () => {
      this.$router.go('/login')
      localStorage.removeItem(this.$config.KEY_USER_TOKEN)
      localStorage.removeItem(this.$config.KEY_OPERATOR)
      location.reload()
    })
    // yesno弹出框
    this.$bus.$on('showYesNo', (title, msg, callback) => {
      this.callbackYesNoConfirm = callback
      this.$confirm(msg, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {
        this.callbackYesNoConfirm()
      }).catch(() => {
      })
    })
    this.$bus.$on('getOperator', () => {
      console.log('getOperator', this.$operator)
      return this.$operator.permissionList
    })
  }
}
</script>

<style lang="scss">
body {
  margin: 0px;
  padding: 0px;
  /*background: url(assets/bg1.jpg) center !important;
    background-size: cover;*/
  // background: #1F2D3D;
  font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
#app {
  position: absolute;
  top: 0px;
  bottom: 0px;
  width: 100%;
}
.el-submenu [class^=fa] {
  vertical-align: baseline;
  margin-right: 10px;
}
.el-menu-item [class^=fa] {
  vertical-align: baseline;
  margin-right: 10px;
}
.toolbar {
  background: #f2f2f2;
  padding: 10px;
  //border:1px solid #dfe6ec;
  margin: 10px 0px;
  .el-form-item {
    margin-bottom: 10px;
  }
}
.fade-enter-active,
.fade-leave-active {
  transition: all .2s ease;
}
.fade-enter,
.fade-leave-active {
  opacity: 0;
}
</style>
